-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Provide more context when mutably borrowing an imutably borrowed value #148508
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Point at statics and consts being mutable borrowed or written to:
```
error[E0594]: cannot assign to immutable static item `NUM`
--> $DIR/E0594.rs:4:5
|
LL | static NUM: i32 = 18;
| --------------- this `static` cannot be written to
...
LL | NUM = 20;
| ^^^^^^^^ cannot assign
```
Point at the expression that couldn't be mutably borrowed from a pattern:
```
error[E0596]: cannot borrow data in a `&` reference as mutable
--> $DIR/mut-pattern-of-immutable-borrow.rs:19:14
|
LL | match &arg.field {
| ---------- this cannot be borrowed as mutable
LL | Some(ref mut s) => s.push('a'),
| ^^^^^^^^^ cannot borrow as mutable
```
|
This PR modifies |
|
r? @nnethercote rustbot has assigned @nnethercote. Use |
| { | ||
| err.span_label( | ||
| local.source_info.span, | ||
| format!("this cannot be {acted_on}"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not seem to have a testcase.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's covered by a few for Boring like in tests/ui/nll/dont-print-desugared.stderr, and tests/ui/pattern/mut-pattern-of-immutable-borrow.rs covers the BlockTailTemp case.
| | | ||
| LL | *input = self.0; | ||
| | ^^^^^^^^^^^^^^^ `input` is a `&` reference, so the data it refers to cannot be written | ||
| | ^^^^^^^^^^^^^^^ `input` is a `&` reference, so the data it refers to cannot be written to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is grammatical. I'd expect either "the reference cannot be written to", or "the data cannot be written"; "to" does not work without indirection.
Perhaps rephrase with "input is a & reference, so *input cannot be written to"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch. changed.
Point at statics and consts being mutable borrowed or written to:
Point at the expression that couldn't be mutably borrowed from a pattern:
Partially address #74617.